package org.budo.dubbo.protocol.http.client;

import org.budo.support.spring.util.SpringUtil;
import org.springframework.beans.factory.FactoryBean;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lmw
 * @see com.alibaba.dubbo.config.spring.ReferenceBean
 * @see com.alibaba.dubbo.config.ReferenceConfig
 */
@Getter
@Setter
public class BudoDubboHttpReferenceFactoryBean implements FactoryBean<Object> {
    private Class<?> interfaceType;

    private BudoDubboProtocolHttpClient httpClient;

    private BudoDubboProtocolHttpClient httpClient() {
        if (null != this.getHttpClient()) {
            return this.getHttpClient();
        }

        return SpringUtil.getBean(BudoDubboProtocolHttpClient.class);
    }

    @Override
    public Object getObject() throws Exception {
        BudoDubboProtocolHttpClient httpClient = this.httpClient();
        return httpClient.getReference(this.getInterfaceType());
    }

    @Override
    public Class<?> getObjectType() {
        return this.interfaceType;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}